/*
 * @desc:
 * @LastEditTime: 2024-03-11 02:44:59
 * @params:
 * @return::
 */
import service from '../request.ts'
import { tokenConfirmFn } from './user.js'

export const getArticles = (data) => {
  return service({
    method: 'GET',
    url: '/article',
    data,
  })
}

export const getArticle = (data) => {
  return service({
    method: 'GET',
    url: `/article/${data.articleId}`,
    data,
  })
}

export const addArticle = (data) => {
  return service({
    method: 'POST',
    url: '/article/create',
    data,
  })
}

export const likeArticle = (data) => {
  return service({
    method: 'POST',
    url: `/article/likeArticle`,
    data,
  })
}

export const addCommentsFn = (data) => {
  return service({
    method: 'PUT',
    url: `/article/addComments`,
    data,
  })
}

export const deleteArticle = (data) => {
  return service({
    method: 'DELETE',
    url: `/article/deleteArticle`,
    data,
  })
}

uni.addInterceptor('request', {
  invoke(args) {
    // 拦截前触发
    // args.url = 'https://www.example.com/'+args.url
    // tokenConfirmFn({}).then((res) => {
    //   if (res.statusCode == 200) {
    //     uni.reLaunch({
    //       url: '/pages/index/index',
    //     })
    //   }
    // })
  },
})
